/*
 *   Copyright (c) 2010 Sonrisa Informatikai Kft. All Rights Reserved.
 * 
 *  This software is the confidential and proprietary information of
 *  Sonrisa Informatikai Kft. ("Confidential Information").
 *  You shall not disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Sonrisa.
 * 
 *  SONRISA MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 *  THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 *  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 *  PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SONRISA SHALL NOT BE LIABLE FOR
 *  ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 *  DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package com.zh.jbet.core.entity;

import com.zh.jbet.core.scorer.GameScorer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Golyo
 */
@XmlRootElement(name = "scorers")
public class BetScorers<T extends Game> {
    private List<GameScorer<T, ? extends Bet>> scorers;
    private Map<Class, GameScorer<T, ? extends Bet>> scorerMap;

    @XmlAnyElement(lax=true)
    public List<GameScorer<T, ? extends Bet>> getScorers() {
        return scorers;
    }

    public void setScorers(List<GameScorer<T, ? extends Bet>> scorers) {
        this.scorers = scorers;
    }

    public void addScorer(GameScorer<T, ? extends Bet> scorer) {
        if (scorers == null) {
            scorers = new ArrayList<GameScorer<T, ? extends Bet>>();
        }
        scorers.add(scorer);
    }

    public <U extends Bet> GameScorer<T, U> getScorer(Class<U> betClass) {
        checkInitMap();
        return (GameScorer<T, U>)scorerMap.get(betClass);
    }
    
    private void checkInitMap() {
        if (scorerMap == null) {
            scorerMap = new HashMap<Class, GameScorer<T, ? extends Bet>>();
            if (scorers != null) {
                for (GameScorer<T, ? extends Bet> scorer: scorers) {
                    scorerMap.put(scorer.getBetClass(), scorer);
                }
            }
        }
    }


}
